package com.example.gkcircle.activity;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import com.example.gkcircle.BaseActivity;
import com.example.gkcircle.R;
import com.example.gkcircle.adapter.BookshelfAdapter;
import com.example.gkcircle.db.DBUtil;

/**
 * Created by Jehu on 16/4/13.
 */
public class BookshelfActivity extends BaseActivity {

    private RecyclerView mRecyclerView;
    private SwipeRefreshLayout mSwipe;
    private BookshelfAdapter mAdapter;
    private BookshelfAdapter.SpaceItemDecoration spaceItemDecoration;

    @Override
    protected void initView() {
        setContentView(R.layout.library_bookshelf_activity);
        mRecyclerView=(RecyclerView)this.findViewById(R.id.library_bookshelf_recyclerview);
        mSwipe=(SwipeRefreshLayout)this.findViewById(R.id.library_bookshelf_swipe);
        mSwipe.setColorSchemeColors(getResources().getColor(R.color.main), getResources().getColor(R.color.love), getResources().getColor(R.color.wish));
        //九宫格布局
        GridLayoutManager glm=new GridLayoutManager(this,3);
        mRecyclerView.setLayoutManager(glm);
        spaceItemDecoration=new BookshelfAdapter.SpaceItemDecoration(15,15,15,15);
        mRecyclerView.addItemDecoration(spaceItemDecoration);
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void setData() {
        mAdapter=new BookshelfAdapter(this, DBUtil.getInstance(this).getBookshelf());
        mRecyclerView.setAdapter(mAdapter);
    }
}
